package com.yunzheng.studyLeaveSystem.modules.admin.show.condition.servlet;
import com.alibaba.fastjson.JSON;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.entity.leaver;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.service.LeaveServiceImpl;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet(name = "condition LeaveServlet",value = "/condition_LeaveServlet")
public class LeaveServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        LeaveServiceImpl leaveService = new LeaveServiceImpl();
        List<leaver> usersList;
        try {
            usersList = leaveService.showDay();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        ResponseWrapper responseWrapper = ResponseWrapper.Success(usersList);
        String s = JSON.toJSONString(responseWrapper);
        PrintWriter writer = response.getWriter();
        writer.println(s);
        System.out.println(s);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
